home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / update~4.z / update~4 / lib_stdio__file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  983 b   |  48 lines

  1. /*                _ f i l e
  2.  *
  3.  * Allocate and initialise a FILE structure. If the pointer passed
  4.  * to the function is NULL, a FILE will be allocated, otherwise
  5.  * the one specified will be used. The function will return
  6.  * a pointer to the FILE structure, or NULL if it fails.
  7.  *
  8.  * Patchlevel 1.0
  9.  *
  10.  * Edit History:
  11.  */
  12.  
  13. #include "stdiolib.h"
  14.  
  15. /*LINTLIBRARY*/
  16.  
  17. #ifdef __STDC__
  18. FILE *_file(FILE *fp, int fd, short flags)
  19. #else
  20. FILE *_file(fp, fd, flags)
  21. FILE *fp;                /* stream */
  22. int fd;                    /* channel */
  23. short flags;                /* flags */
  24. #endif
  25. {
  26. #ifdef __STDC__
  27.   void *malloc(unsigned int);            /* memory allocator */
  28. #else
  29.   void *malloc();            /* memory allocator */
  30. #endif
  31.  
  32. /* Allocate a file structure */
  33.   if (fp == NULL)
  34.     fp = (FILE *) malloc((unsigned int)(sizeof(*fp)));
  35.  
  36. /* Now initialise the structure */
  37.   if (fp != NULL) {
  38.     fp->_end    = NULL;
  39.     fp->_ptr    = NULL;
  40.     fp->_base   = NULL;
  41.     fp->_bufsiz = 0;
  42.     fp->_flag   = flags;
  43.     fp->_file   = fd;
  44.   }
  45.  
  46.   return fp;
  47. }
  48.